package com.xjl.common.mybatisplus.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Slf4j
public class MetaDataHandler implements MetaObjectHandler {


    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("MetaObjectHandler---insertFill");
        this.strictInsertFill(metaObject,"createdBy",String.class,"xxx");
        this.strictInsertFill(metaObject,"createdTime", Date.class,new Date());
        this.strictInsertFill(metaObject,"isDeleted", Integer.class,0);
        this.strictInsertFill(metaObject,"version", Integer.class,0);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("MetaObjectHandler---updateFill");
        this.strictUpdateFill(metaObject,"updateBy",String.class,"xxx");
        this.strictUpdateFill(metaObject,"updateTime",Date.class,new Date());
    }
}
